<template>
  <div class="theme-active-text-color content">
    <div class="form_content">
      <el-form :model="dataForm" :rules="rules" ref="dataForm" label-width="100px" class="demo-dataForm">
      <el-form-item label="合同编号:" prop="agree_id">
        <el-input v-model="dataForm.agree_id"></el-input>
      </el-form-item>
      <el-form-item label="涉及品类:" prop="kind">
        <el-input v-model="dataForm.kind"></el-input><span>不同种类使用','分隔,至少填入一种品类</span>
      </el-form-item>
       <el-form-item label="签订单价:" prop="price">
        <el-input v-model="dataForm.price"></el-input><span>使用','分隔，与品类一一对应</span>
      </el-form-item>
       <el-form-item label="采购商家:" prop="merchant">
        <el-input v-model="dataForm.merchant"></el-input>
      </el-form-item>
      <el-form-item label="签订时间:" prop="sign_time">
        <el-date-picker
          v-model="dataForm.sign_time"
          type="date"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="合同签订人:" prop="applyer">
        <el-input v-model="dataForm.applyer"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('dataForm')">提交</el-button>
        <el-button @click="resetForm('dataForm')">重置</el-button>
      </el-form-item>
    </el-form>
    </div>
  </div>
</template>

<script>
import { agreeInputApi } from '@/api'
export default {
  name: "",
  components: {},
  data() {
    return {
      dataForm: {
          agree_id: '',
          kind:'',
          price:'',
          merchant:'',
          applyer:'',
          sign_time:''
        },
        rules: {
          kind: [{ required: true, message: '请输入至少一种品类', trigger: 'blur' }],
          agree_id: [{ required: true, message: '请填写合同编号', trigger: 'blur' }],
          price:[{required: true, message: '请输入合同价格', trigger: 'blur'}],
          sign_time:[{required: true, message: '请输入签订时间', trigger: 'blur'}],
          merchant:[{required: true, message: '请输入采购商家', trigger: 'blur'}],
          applyer:[{required: true, message: '请输入合同签订人', trigger: 'blur'}],
        }
    };
  },
  created() {},
  methods: {
    submitForm() {
      let _this=this;
        this.$refs.dataForm.validate(async (valid) => {
          if (valid) {
            _this.dataForm.sign_time = _this.dataForm.sign_time.getTime()
           let res = await agreeInputApi(_this.dataForm);
            if(res.code=='200'){
              _this.$message({
                message: '申请成功',
                type: 'success'
              });
            }else{
              _this.$message({
                message: '申请失败',
                type: 'error'
              });
            }
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm() {
        this.$refs.dataForm.resetFields();
      }
     
  }
};
</script>
<style lang="less" scoped>
.content{
  width: 100%;
  height: 100%;
  background: #fff;
  box-sizing: border-box;
  display: flex;
  overflow-y: auto;
  .form_content{
    width: 400px;
    height: 90%;
    padding: 50px 10px 10px 20px;
    .el-input{
      width: 300px;
    }
  }
}

</style>